package com.codepuzzler;

import java.util.HashSet;
import java.util.Set;

public class TreeNode {
    private String label;
    private int value;
    private TreeNode parent;
    private Set<TreeNode> children = new HashSet<TreeNode>();

    public TreeNode(String label, int value) {
        this.label = label;
        this.value = value;
    }

    public void addChild(TreeNode child) {
        children.add(child);
    }

    boolean isLeaf() {
        return children.isEmpty();
    }

    boolean isMinimumTree() {
        if (isLeaf()) return false;

        for (TreeNode child : children) {
            if (child != null && !child.isLeaf()) {
                return false;
            }
        }

        return true;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public int getValue() {
        return value;
    }

    public void setValue(int value) {
        this.value = value;
    }

    public TreeNode getParent() {
        return parent;
    }

    public void setParent(TreeNode parent) {
        this.parent = parent;
    }

    public Set<TreeNode> getChildren() {
        return children;
    }

    public void setChildren(Set<TreeNode> children) {
        this.children = children;
    }
}
